package com.hu.zhcc.shiro.controller.Lixueseng520;

import com.hu.zhcc.common.entity.Page;
import com.hu.zhcc.shiro.entity.bo.Lixueseng520.LxsProgram;
import com.hu.zhcc.shiro.entity.bo.Lixueseng520.LxsProgramSort;
import com.hu.zhcc.shiro.service.Lixueseng520.ProgramService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("program")
public class ProgramController {
    @Autowired
    private ProgramService programService;

    // 查询
    @GetMapping("")
    public Page<LxsProgram> getProgramList(String encode, Integer sid
            , Integer offset, Integer limit) {
        Map map = new HashMap();
        map.put("sid", sid);
        return programService.findProgramByPrimary(map, offset, limit);
    }


    // 添加
    @PostMapping("add")
    public int saveProgram(@RequestBody LxsProgram program) {
        programService.insertSelective(program);
        program.setEncode("FA000" + program.getId());
        return programService.updateByPrimaryKeySelective(program);
    }

    // 修改
    @PutMapping("/{id}")
    public int getProgramById(@PathVariable("id") int id, @RequestBody LxsProgram program) {
        return programService.updateByPrimaryKeySelective(program);
    }

    // 删除
    @DeleteMapping("/{id}")
    public int removeProgram(@PathVariable("id") int id) {
        return programService.deleteByPrimaryKey(id);
    }
}
